﻿using System;
using System.ComponentModel;
using System.Globalization;

namespace Gmantis.Controls.DataGrid
{
    public class DataGridScrollStepConverter : TypeConverter
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return ((sourceType.Name == "String") || base.CanConvertFrom(context, sourceType));
        }

        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                double num;
                string s = value as string;
                if (s == "Discrete")
                {
                    return DataGridScrollStep.Discrete;
                }
                if (double.TryParse(s, out num))
                {
                    return new DataGridScrollStep(num);
                }
            }
            return base.ConvertFrom(context, culture, value);
        }
    }
}
